function [FY, F] = featuresConcatenation( Y, X, d)

[M, N] = size(X);

%calculate new dimenssions
f_examples = M - d;
f_features = d * N;

%alocate features and prediction matrix
F = zeros(f_examples,f_features);
FY = zeros(f_examples,1); 

%position in the target vector
newPosition = f_examples;
%position in the old y vector
npy = size(Y,1);

%loop through X matrix
for i = M:-1:1
   %get the interval of historcal data
   st_int = i - d;
   end_int = i - 1 ;
   
   %assign as new features
   F(newPosition,:) = reshape(X(st_int:end_int,:),1, f_features);
   %create the
   FY(newPosition,1) = Y(npy,1);
    
   %update variables
   newPosition = newPosition - 1;
   npy = npy - 1;
   
   %if excedds the matrix limits
    if(npy == 0)
       break;
    end;
   
   if(newPosition == 0)
       break;
   end;
end;

    
end